using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Domain.Services;
using Volo.Abp.Data;

namespace SanJ.FreeCare.Medications
{
    public abstract class MedicationManagerBase : DomainService
    {
        protected IMedicationRepository _medicationRepository;

        public MedicationManagerBase(IMedicationRepository medicationRepository)
        {
            _medicationRepository = medicationRepository;
        }

        public virtual async Task<Medication> CreateAsync(
        decimal anitDDDValue, decimal clinicSaleVolume, decimal defultDoseVolume, decimal secondDoseVolume, decimal retailPrice, decimal defaultDoseVolume, string? code = null, string? statusCode = null, string? keyWord = null, string? productName = null, string? productNamePY = null, string? productNameWB = null, string? productNameEN = null, string? alias = null, string? aliasPY = null, string? aliasWB = null, string? aliasEN = null, string? scientificName = null, string? scientificNamePY = null, string? scientificNameWB = null, string? scientificNameEN = null, string? antiLevelCode = null, string? antiClassCode1 = null, string? antiClassCode2 = null, string? anitDDDUnitCode = null, decimal? antiOnceMinValue = null, decimal? antiOnceMaxValue = null, string? antiOnceUnitCode = null, int? antiFrequencyMin = null, int? antiFrequencyMax = null, string? gBCode = null, string? typeCode = null, string? classCode = null, string? feeTypeCode = null, string? specialTypeCode = null, string? levelCode = null, string? doseFormCode = null, string? specification = null, string? baseUnitCode = null, string? clinicSaleUnitCode = null, string? inpatientSaleUnitCode = null, string? inpatientSaleVolume = null, string? transportUnitCode = null, string? transportVolume = null, string? defaultDoseUnitCode = null, string? secondDoseUnitCode = null, string? defaultUsageCode = null, string? defaultFrequencyCode = null, string? skinTestFlag = null, string? skinTestNeedFlag = null, string? skinTestTypeFlag = null, string? skinTestCode = null)
        {

            var medication = new Medication(
             GuidGenerator.Create(),
             anitDDDValue, clinicSaleVolume, defultDoseVolume, secondDoseVolume, retailPrice, defaultDoseVolume, code, statusCode, keyWord, productName, productNamePY, productNameWB, productNameEN, alias, aliasPY, aliasWB, aliasEN, scientificName, scientificNamePY, scientificNameWB, scientificNameEN, antiLevelCode, antiClassCode1, antiClassCode2, anitDDDUnitCode, antiOnceMinValue, antiOnceMaxValue, antiOnceUnitCode, antiFrequencyMin, antiFrequencyMax, gBCode, typeCode, classCode, feeTypeCode, specialTypeCode, levelCode, doseFormCode, specification, baseUnitCode, clinicSaleUnitCode, inpatientSaleUnitCode, inpatientSaleVolume, transportUnitCode, transportVolume, defaultDoseUnitCode, secondDoseUnitCode, defaultUsageCode, defaultFrequencyCode, skinTestFlag, skinTestNeedFlag, skinTestTypeFlag, skinTestCode
             );

            return await _medicationRepository.InsertAsync(medication);
        }

        public virtual async Task<Medication> UpdateAsync(
            Guid id,
            decimal anitDDDValue, decimal clinicSaleVolume, decimal defultDoseVolume, decimal secondDoseVolume, decimal retailPrice, decimal defaultDoseVolume, string? code = null, string? statusCode = null, string? keyWord = null, string? productName = null, string? productNamePY = null, string? productNameWB = null, string? productNameEN = null, string? alias = null, string? aliasPY = null, string? aliasWB = null, string? aliasEN = null, string? scientificName = null, string? scientificNamePY = null, string? scientificNameWB = null, string? scientificNameEN = null, string? antiLevelCode = null, string? antiClassCode1 = null, string? antiClassCode2 = null, string? anitDDDUnitCode = null, decimal? antiOnceMinValue = null, decimal? antiOnceMaxValue = null, string? antiOnceUnitCode = null, int? antiFrequencyMin = null, int? antiFrequencyMax = null, string? gBCode = null, string? typeCode = null, string? classCode = null, string? feeTypeCode = null, string? specialTypeCode = null, string? levelCode = null, string? doseFormCode = null, string? specification = null, string? baseUnitCode = null, string? clinicSaleUnitCode = null, string? inpatientSaleUnitCode = null, string? inpatientSaleVolume = null, string? transportUnitCode = null, string? transportVolume = null, string? defaultDoseUnitCode = null, string? secondDoseUnitCode = null, string? defaultUsageCode = null, string? defaultFrequencyCode = null, string? skinTestFlag = null, string? skinTestNeedFlag = null, string? skinTestTypeFlag = null, string? skinTestCode = null, [CanBeNull] string? concurrencyStamp = null
        )
        {

            var medication = await _medicationRepository.GetAsync(id);

            medication.AnitDDDValue = anitDDDValue;
            medication.ClinicSaleVolume = clinicSaleVolume;
            medication.DefultDoseVolume = defultDoseVolume;
            medication.SecondDoseVolume = secondDoseVolume;
            medication.RetailPrice = retailPrice;
            medication.DefaultDoseVolume = defaultDoseVolume;
            medication.Code = code;
            medication.StatusCode = statusCode;
            medication.KeyWord = keyWord;
            medication.ProductName = productName;
            medication.ProductNamePY = productNamePY;
            medication.ProductNameWB = productNameWB;
            medication.ProductNameEN = productNameEN;
            medication.Alias = alias;
            medication.AliasPY = aliasPY;
            medication.AliasWB = aliasWB;
            medication.AliasEN = aliasEN;
            medication.ScientificName = scientificName;
            medication.ScientificNamePY = scientificNamePY;
            medication.ScientificNameWB = scientificNameWB;
            medication.ScientificNameEN = scientificNameEN;
            medication.AntiLevelCode = antiLevelCode;
            medication.AntiClassCode1 = antiClassCode1;
            medication.AntiClassCode2 = antiClassCode2;
            medication.AnitDDDUnitCode = anitDDDUnitCode;
            medication.AntiOnceMinValue = antiOnceMinValue;
            medication.AntiOnceMaxValue = antiOnceMaxValue;
            medication.AntiOnceUnitCode = antiOnceUnitCode;
            medication.AntiFrequencyMin = antiFrequencyMin;
            medication.AntiFrequencyMax = antiFrequencyMax;
            medication.GBCode = gBCode;
            medication.TypeCode = typeCode;
            medication.ClassCode = classCode;
            medication.FeeTypeCode = feeTypeCode;
            medication.SpecialTypeCode = specialTypeCode;
            medication.LevelCode = levelCode;
            medication.DoseFormCode = doseFormCode;
            medication.Specification = specification;
            medication.BaseUnitCode = baseUnitCode;
            medication.ClinicSaleUnitCode = clinicSaleUnitCode;
            medication.InpatientSaleUnitCode = inpatientSaleUnitCode;
            medication.InpatientSaleVolume = inpatientSaleVolume;
            medication.TransportUnitCode = transportUnitCode;
            medication.TransportVolume = transportVolume;
            medication.DefaultDoseUnitCode = defaultDoseUnitCode;
            medication.SecondDoseUnitCode = secondDoseUnitCode;
            medication.DefaultUsageCode = defaultUsageCode;
            medication.DefaultFrequencyCode = defaultFrequencyCode;
            medication.SkinTestFlag = skinTestFlag;
            medication.SkinTestNeedFlag = skinTestNeedFlag;
            medication.SkinTestTypeFlag = skinTestTypeFlag;
            medication.SkinTestCode = skinTestCode;

            medication.SetConcurrencyStampIfNotNull(concurrencyStamp);
            return await _medicationRepository.UpdateAsync(medication);
        }

    }
}